<?php

namespace App\B2BProject\Custom\Purchaser;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Query\Builder;

class CounterEnquiry extends Model
{
    protected $guarded = ['id', 'created_at', 'updated_at'];

    public function enquiry()
    {
        return $this->belongsTo('App\B2BProject\Custom\Purchaser\Enquiry', 'enquiry_id', 'id');
    }

    /**
     * 标识为已处理
     *
     * @return bool
     */
    public function deal()
    {
        $this->status = true;

        return $this->save();
    }

    /**
     * 设置状态条件
     *
     * @param Builder $query
     * @param         $status
     *
     * @return $this
     */
    public function scopeWhereStatus(Builder $query, $status)
    {
        return $query->where('status', $status);
    }

    /**
     * 发布者
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function publisher()
    {
        return $this->belongsTo('App\B2BProject\Custom\Member', 'member_id', 'id');
    }
}
